home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT12 / WINC07.C < prev   
Encoding:
C/C++ Source or Header  |  1992-08-18  |  6.8 KB  |  136 lines

  1.  
  2. /*---------------------------------------------------------------------*
  3. *                                                                      *
  4. *  The line editing with the insert/overriding modes usage             *
  5. *                                                                      *
  6. *                                                                      *
  7. *  Parameters (the same as for program DIAM04)                         *
  8. *                                                                      *
  9. *  M  - number of row (1 - 50)                                         *
  10. *                                                                      *
  11. *  T  - the address of the prompt string                               *
  12. *                                                                      *
  13. *  L  - the length of the string (1 - 80)                              *
  14. *                                                                      *
  15. *  V  - initial position of the cursor within prompt string            *
  16. *                                                                      *
  17. *  Q  - command line enterd by user                                    *
  18. *                                                                      *
  19. *  S  - the cursor position within the command line when ENTER pressed *
  20. *                                                                      *
  21. *  W  - the array containing ASCII and scan codes for key pressed and  *
  22. *       values of bytes 417h and 418h (keyboard flags)                 * 
  23. *                                                                      *
  24. *  I  - array containing the screen parameters                         *
  25. *                                                                      *
  26. *                                                                      *
  27. *  Additional parametrs:                                               *
  28. *                                                                      *
  29. *  RL - left bound of the cursor within the command line               *
  30. *                                                                      *
  31. *  RR - right bound of the cursor within the command line              *
  32. *                                                                      *
  33. *  If RR = 0  or LL = 0  the whole string is processed                 *
  34. *                                                                      *
  35. *                                                                      *
  36. *  The exit is performed when ESC or Enter key is pressed              *
  37. *                                                                      *
  38. *---------------------------------------------------------------------*/
  39.  
  40.  
  41. extern void DIAM04 (int OP, int M, int N, char *T, int L, int U, int V,
  42.                     int *Q, int *S, char *W, char *I);
  43.  
  44.  
  45. void WINC07 (int M, char *T, int L, int V, int *Q, int *S, char *W,
  46.              char *I, int RL, int RR)
  47.  
  48. {
  49.  
  50. int  D0, j;
  51.  
  52. /* ----------------------------------------------------------------------- */
  53. /*  Waiting for a key and processing the code of key pressed              */
  54.  
  55.       *W = *(W+1) = 0;
  56.       D0 = (I == 0) ? 0 : *(I+1);
  57.       RL = (RL == 0) ? D0+1 : RL;
  58.       RR = (RR == 0) ? L+D0 : RR;
  59.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  60.       while ((*(W+1) != 1) && (*(W+1) != 0x1c))
  61.  {
  62.       DIAM14 (W);            /*  check keyboard buffer                     */
  63.       switch (*(W+1))        /*  process the code of key pressed           */
  64.   {
  65. /*----------------------------------------------------------------------
  66.     Processing the keys which must be ignored
  67. -----------------------------------------------------------------------*/
  68.  
  69. case  0x45:                  /*  "Num Lock"                                */
  70. case  0x46:                  /*  "Scroll Lock"                             */
  71. case  0x48:                  /*  Up Arrow                                  */
  72. case  0x50:                  /*  Down Arrow                                */
  73. case  0x52:                  /*  "Ins"                                     */
  74.              break;
  75. /* ----------------------------------------------------------------------- */
  76. case  0x0f:                  /*  the Tab key                               */
  77.  
  78.       if (*W != 0)           /*  Tab to the right (Tab)                    */
  79.          break;
  80.       else                   /*  Tab to the left  (Shift + Tab)            */
  81.          break;
  82. /* ----------------------------------------------------------------------- */
  83. case  0x4d:                  /*  Right Arrow                               */
  84.       V = (V == RR) ? V : ++V;
  85.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  86.       break;
  87. /* ----------------------------------------------------------------------- */
  88. case  0x4b:                  /*  Left Arrow                                */
  89.       V = (V == RL) ? V : --V;
  90.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  91.       break;
  92. /* ----------------------------------------------------------------------- */
  93. case  0x47:                  /*  The "Home" key - beginning of the string  */
  94.       V = RL;
  95.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  96.       break;
  97. /* ----------------------------------------------------------------------- */
  98. case  0x4f:                  /*  The "End" key - end of the string         */
  99.       V = RR;
  100.       while ((*(T -D0 -1 +(--V))) <= ' ') 
  101.          ;
  102.       ++V;
  103.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  104.       break;
  105. /* ----------------------------------------------------------------------- */
  106. case  0x0e:                  /*  the "<--" key - Backspace                 */
  107.       if (V == RL)   break;
  108.       --V;
  109.       for (j = V -D0; j < RR -D0; j++)  *(T+j-1) = *(T+j);
  110.       *(T+j-1) = ' ';
  111.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  112.       break;
  113. /* ----------------------------------------------------------------------- */
  114. case  0x53:                  /*  the Del key - delete character            */
  115.       for (j = V -D0; j < RR -D0; j++)  *(T+j-1) = *(T+j);
  116.       *(T+j-1) = ' ';
  117.       DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  118.       break;
  119. /*----------------------------------------------------------------------
  120.     Processing keys that generate ASCII characters
  121. -----------------------------------------------------------------------*/
  122. default:                             /* ASCII  codes except Enter and ESC */
  123.   if ((*W != 0) && (*W != 0x0d) && (*W != 0x1b))
  124.      {
  125.        for (j = RR-D0-2; j >= V -D0 -1; j--)  *(T+j+1) = *(T+j);
  126.        *(T+j+1) = *W;
  127.        V = (V == RR) ? V : ++V;
  128.        DIAM05 (1, M, M, T, L, M, V, Q, S, W, I);
  129.      }
  130.        break;                /*  if other keys - exit                    */
  131.   }   /*  end    switch (*(W+1))  */
  132.  }    /*  end    while    */
  133.        return;
  134. }     /*  end    WINC07    */
  135.  
  136.